package com.AndroidUI;

import java.util.ArrayList;

import com.Domain.Channel;
import com.EdificacioAR.DebugLog;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;


public class ChannelAdapter extends BaseAdapter {
	
	private static final String TAG = "ChannelAdapter";
	
	private Context context;
	private ArrayList<Channel> channelList;
	

	
	public ChannelAdapter(Context context) {
		this.context = context;
		this.channelList = new ArrayList<Channel>();
	}
	
	public void addChannel(Channel channel) {
		this.channelList.add(channel);
	}

	@Override
	public int getCount() {
		return this.channelList.size();
	}

	@Override
	public Object getItem(int position) {
		return this.channelList.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		// Not needed
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ChannelElement channel;
		
		if (convertView == null) {
			channel = new ChannelElement(context);
			//TODO: layout parameters
		}
		else {
			channel = (ChannelElement)convertView; 
		}
		
		//DebugLog.LOGD(TAG + " - " +  this.channelList.get(position).getName());
		channel.initialize(position, this.channelList.get(position).getName());
		return channel;
		
		/*
		ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
        */
	}

}
